package com.zhanbo.zhanbowymusic.main;

import android.os.Bundle;
import android.view.View;

import com.mwx.baselib.base.BaseFragment;
import com.mwx.baselib.constant.Constant;
import com.mwx.baselib.utils.SPUtils;
import com.mwx.baselib.utils.ToastUtils;
import com.zhanbo.zhanbowymusic.R;
import com.zhanbo.zhanbowymusic.databinding.FragmentSettingBinding;

/**
 * 设置页面
 */
public class SettingFragment extends BaseFragment<FragmentSettingBinding> implements View.OnClickListener {

    @Override
    protected Object getLayout() {
        return R.layout.fragment_setting;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        initData();
        initListener();
    }

    @Override
    protected void initData() {
        if ((boolean)SPUtils.get(Constant.AUTO_PLAY,false)){
            binding.ivAuto.setImageResource(R.mipmap.rb_check);
        }else {
            binding.ivAuto.setImageResource(R.mipmap.rb_uncheck);
        }
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initListener() {
        binding.ivBack.setOnClickListener(this);
        binding.llBiaoZhun.setOnClickListener(this);
        binding.llGaoJieXi.setOnClickListener(this);
        binding.llHuanRao.setOnClickListener(this);
        binding.llMuDai.setOnClickListener(this);
        binding.llJiGao.setOnClickListener(this);
        binding.llWuSun.setOnClickListener(this);
        binding.llZhenYin.setOnClickListener(this);
        binding.llBai.setOnClickListener(this);
        binding.llHei.setOnClickListener(this);
        binding.llAuto.setOnClickListener(this);
        binding.tvClear.setOnClickListener(this);
    }

    public static SettingFragment newInstance() {

        Bundle args = new Bundle();

        SettingFragment fragment = new SettingFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                pop();
                break;
            case R.id.tv_clear:
                ToastUtils.showLongToast(_mActivity,"清除成功");
                break;
            case R.id.ll_biao_zhun:
                closeYinZhiCheck();
                binding.ivBiaoZhun.setImageResource(R.mipmap.rb_check);
                break;
            case R.id.ll_gao_jie_xi:
                closeYinZhiCheck();
                binding.ivGaoJieXi.setImageResource(R.mipmap.rb_check);
                break;
            case R.id.ll_huan_rao:
                closeYinZhiCheck();
                binding.ivHuanRao.setImageResource(R.mipmap.rb_check);
                break;
            case R.id.ll_mu_dai:
                closeYinZhiCheck();
                binding.ivMuDai.setImageResource(R.mipmap.rb_check);
                break;
            case R.id.ll_ji_gao:
                closeYinZhiCheck();
                binding.ivJiGao.setImageResource(R.mipmap.rb_check);
                break;
            case R.id.ll_wu_sun:
                closeYinZhiCheck();
                binding.ivWuSun.setImageResource(R.mipmap.rb_check);
                break;
            case R.id.ll_zhen_yin:
                closeYinZhiCheck();
                binding.ivZhenYin.setImageResource(R.mipmap.rb_check);
                break;
            case R.id.ll_bai:
                binding.ivHei.setImageResource(R.mipmap.rb_uncheck);
                binding.ivBai.setImageResource(R.mipmap.rb_check);
                break;
            case R.id.ll_hei:
                binding.ivBai.setImageResource(R.mipmap.rb_uncheck);
                binding.ivHei.setImageResource(R.mipmap.rb_check);
                break;
            case R.id.ll_auto:
                if ((boolean)SPUtils.get(Constant.AUTO_PLAY,false)){
                    binding.ivAuto.setImageResource(R.mipmap.rb_uncheck);
                    SPUtils.put(Constant.AUTO_PLAY,false);
                }else {
                    binding.ivAuto.setImageResource(R.mipmap.rb_check);
                    SPUtils.put(Constant.AUTO_PLAY,true);
                }


                break;
        }
    }

    private void closeYinZhiCheck() {
        binding.ivBiaoZhun.setImageResource(R.mipmap.rb_uncheck);
        binding.ivGaoJieXi.setImageResource(R.mipmap.rb_uncheck);
        binding.ivHuanRao.setImageResource(R.mipmap.rb_uncheck);
        binding.ivMuDai.setImageResource(R.mipmap.rb_uncheck);
        binding.ivJiGao.setImageResource(R.mipmap.rb_uncheck);
        binding.ivWuSun.setImageResource(R.mipmap.rb_uncheck);
        binding.ivZhenYin.setImageResource(R.mipmap.rb_uncheck);

    }
}